package servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import domain.User;
import service.MonthCallNumberService;
import service.MonthCallTimeService;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/MonthCallNumberServlet")
public class MonthCallNumberServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.v->c:从页面读取参数，利用req对象
        Object user = req.getSession().getAttribute("user");
        ObjectMapper objectMapper = new ObjectMapper();
        User user3 = (User) user;

        //2.c->m->c：处理数据，调用DAO访问数据库，同时得到返回值0
        MonthCallNumberService contactsService = new MonthCallNumberService();
        String json3 = contactsService.ToJson3(user3);

        System.out.println(json3);

        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json3);
    }
}
